package Core.Map;

import Core.Character;

public class CharacterMoverImpl implements CharacterMover {

	@Override
	public void moveCharacter(CombatGrid grid, Character character, int destinationX,
			int destinationY)
	{
			this.removeCharacter(grid, character);
			this.insertCharacter(grid, character, destinationX, destinationY);
	}
	
	private void removeCharacter(CombatGrid grid, Character character)
	{
		Tile oldTile = grid.getTileWithCharacter(character);
		
		if (oldTile != null)
		{
			oldTile.removeCharacter(character);
		}
	}
	
	private void insertCharacter(CombatGrid grid, Character character, int x, int y)
	{
		Tile newTile = grid.getTile(x, y);
		
		newTile.addCharacter(character);
	}
}
